<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\facade\Builder;
use think\App;
use think\response\Json;

class Draw extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\Draw';

    //关联模型
    protected array $hasOne = ['user'];

    public function index(): string
    {
        return Builder::Table()
            ->addColumn(['type' => 'checkbox', 'fixed' => 'left', 'title' => '全选'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'uid', 'title' => '相关会员', 'templet' => '#_userTpl', 'width' => 250])
            ->addColumn(['field' => 'account', 'title' => '账户'])
            ->addColumn(['field' => 'amount', 'title' => '提现金额'])
            ->addColumn(['field' => 'cost', 'title' => '手续费'])
            ->addColumn(['field' => 'real_amount', 'title' => '实际到账金额'])
            ->addColumn(['field' => 'mode', 'title' => '提现方式'])
            ->addColumn(['field' => 'create_time', 'title' => '申请时间', 'width' => 150])
            ->addColumn(['field' => 'status', 'title' => '状态'])
            ->addColumn(['field' => 'admin_name', 'title' => '审核人'])
            ->addColumn(['field' => 'confirm_time', 'title' => '审核时间'])
            ->addColumn(['field' => 'reject_msg', 'title' => '驳回原因'])
            ->addColumn(['fixed' => 'right', 'title' => '操作', 'align' => 'center', 'toolbar' => '#barDemo', 'width' => 120])
            ->addRightButtons(['edit' => ['title' => '查看']])
            ->addTopButtons([
                'batchPass' => [
                    'title' => '批量通过', 'icon' => 'layui-icon-util',
                    'class' => 'normal',
                    'url'   => url('draw/batchPass')->build(),
                    'event' => '_batchSubmit'
                ],
                'batchReject' => [
                    'title' => '批量驳回', 'icon' => 'layui-icon-util',
                    'url'   => url('draw/batchReject')->build(),
                    'event' => '_batchSubmit'
                ],
                'export'])
            ->addSearch([
                ['uid', '会员编号/昵称/手机号', 'input', '', '\app\common\model\User', 'code|nickname|mobile,id'],
                ['status', '状态', 'select', getExamineStatus()]
            ])
            ->fetch();
    }

    public function edit($id = '', $tpl = 'draw/edit', $info = ''): string
    {
        return parent::edit($id, $tpl, $info); // TODO: Change the autogenerated stub
    }

    public function save($param = [], $model = true): Json
    {
        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }

    public function batchPass()
    {
        return $this->model::batchPass($this->request->param('ids'), $this->admin);
    }

    public function batchReject()
    {
        return $this->model::batchReject($this->request->param('ids'), $this->admin);
    }
}